home *** CD-ROM | disk | FTP | other *** search
- package javax.swing.tree;
-
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.Graphics;
- import javax.swing.Icon;
- import javax.swing.JComponent;
- import javax.swing.JLabel;
- import javax.swing.JTree;
- import javax.swing.UIManager;
- import javax.swing.plaf.ColorUIResource;
- import javax.swing.plaf.FontUIResource;
-
- public class DefaultTreeCellRenderer extends JLabel implements TreeCellRenderer {
- protected boolean selected;
- private boolean hasFocus;
- private boolean drawsFocusBorderAroundIcon;
- protected transient Icon closedIcon;
- protected transient Icon leafIcon;
- protected transient Icon openIcon;
- protected Color textSelectionColor;
- protected Color textNonSelectionColor;
- protected Color backgroundSelectionColor;
- protected Color backgroundNonSelectionColor;
- protected Color borderSelectionColor;
-
- public DefaultTreeCellRenderer() {
- ((JLabel)this).setHorizontalAlignment(2);
- this.setLeafIcon(UIManager.getIcon("Tree.leafIcon"));
- this.setClosedIcon(UIManager.getIcon("Tree.closedIcon"));
- this.setOpenIcon(UIManager.getIcon("Tree.openIcon"));
- this.setTextSelectionColor(UIManager.getColor("Tree.selectionForeground"));
- this.setTextNonSelectionColor(UIManager.getColor("Tree.textForeground"));
- this.setBackgroundSelectionColor(UIManager.getColor("Tree.selectionBackground"));
- this.setBackgroundNonSelectionColor(UIManager.getColor("Tree.textBackground"));
- this.setBorderSelectionColor(UIManager.getColor("Tree.selectionBorderColor"));
- Object var1 = UIManager.get("Tree.drawsFocusBorderAroundIcon");
- this.drawsFocusBorderAroundIcon = var1 != null && (Boolean)var1;
- }
-
- public Color getBackgroundNonSelectionColor() {
- return this.backgroundNonSelectionColor;
- }
-
- public Color getBackgroundSelectionColor() {
- return this.backgroundSelectionColor;
- }
-
- public Color getBorderSelectionColor() {
- return this.borderSelectionColor;
- }
-
- public Icon getClosedIcon() {
- return this.closedIcon;
- }
-
- public Icon getDefaultClosedIcon() {
- return UIManager.getIcon("Tree.closedIcon");
- }
-
- public Icon getDefaultLeafIcon() {
- return UIManager.getIcon("Tree.leafIcon");
- }
-
- public Icon getDefaultOpenIcon() {
- return UIManager.getIcon("Tree.openIcon");
- }
-
- private int getLabelStart() {
- Icon var1 = ((JLabel)this).getIcon();
- return var1 != null && ((JLabel)this).getText() != null ? var1.getIconWidth() + Math.max(0, ((JLabel)this).getIconTextGap() - 1) : 0;
- }
-
- public Icon getLeafIcon() {
- return this.leafIcon;
- }
-
- public Icon getOpenIcon() {
- return this.openIcon;
- }
-
- public Dimension getPreferredSize() {
- Dimension var1 = super.getPreferredSize();
- if (var1 != null) {
- var1 = new Dimension(var1.width + 3, var1.height);
- }
-
- return var1;
- }
-
- public Color getTextNonSelectionColor() {
- return this.textNonSelectionColor;
- }
-
- public Color getTextSelectionColor() {
- return this.textSelectionColor;
- }
-
- public Component getTreeCellRendererComponent(JTree var1, Object var2, boolean var3, boolean var4, boolean var5, int var6, boolean var7) {
- String var8 = var1.convertValueToText(var2, var3, var4, var5, var6, var7);
- this.hasFocus = var7;
- ((JLabel)this).setText(var8);
- if (var3) {
- ((JComponent)this).setForeground(this.getTextSelectionColor());
- } else {
- ((JComponent)this).setForeground(this.getTextNonSelectionColor());
- }
-
- if (!((Component)var1).isEnabled()) {
- ((JComponent)this).setEnabled(false);
- if (var5) {
- ((JLabel)this).setDisabledIcon(this.getLeafIcon());
- } else if (var4) {
- ((JLabel)this).setDisabledIcon(this.getOpenIcon());
- } else {
- ((JLabel)this).setDisabledIcon(this.getClosedIcon());
- }
- } else {
- ((JComponent)this).setEnabled(true);
- if (var5) {
- ((JLabel)this).setIcon(this.getLeafIcon());
- } else if (var4) {
- ((JLabel)this).setIcon(this.getOpenIcon());
- } else {
- ((JLabel)this).setIcon(this.getClosedIcon());
- }
- }
-
- this.selected = var3;
- return this;
- }
-
- public void paint(Graphics var1) {
- Color var2;
- if (this.selected) {
- var2 = this.getBackgroundSelectionColor();
- } else {
- var2 = this.getBackgroundNonSelectionColor();
- if (var2 == null) {
- var2 = ((Component)this).getBackground();
- }
- }
-
- int var3 = -1;
- if (var2 != null) {
- Icon var4 = ((JLabel)this).getIcon();
- var3 = this.getLabelStart();
- var1.setColor(var2);
- var1.fillRect(var3, 0, ((JComponent)this).getWidth() - 1 - var3, ((JComponent)this).getHeight());
- }
-
- if (this.hasFocus) {
- if (this.drawsFocusBorderAroundIcon) {
- var3 = 0;
- } else if (var3 == -1) {
- var3 = this.getLabelStart();
- }
-
- Color var5 = this.getBorderSelectionColor();
- if (var5 != null) {
- var1.setColor(var5);
- var1.drawRect(var3, 0, ((JComponent)this).getWidth() - 1 - var3, ((JComponent)this).getHeight() - 1);
- }
- }
-
- super.paint(var1);
- }
-
- public void setBackground(Color var1) {
- if (var1 instanceof ColorUIResource) {
- var1 = null;
- }
-
- super.setBackground(var1);
- }
-
- public void setBackgroundNonSelectionColor(Color var1) {
- this.backgroundNonSelectionColor = var1;
- }
-
- public void setBackgroundSelectionColor(Color var1) {
- this.backgroundSelectionColor = var1;
- }
-
- public void setBorderSelectionColor(Color var1) {
- this.borderSelectionColor = var1;
- }
-
- public void setClosedIcon(Icon var1) {
- this.closedIcon = var1;
- }
-
- public void setFont(Font var1) {
- if (var1 instanceof FontUIResource) {
- var1 = null;
- }
-
- super.setFont(var1);
- }
-
- public void setLeafIcon(Icon var1) {
- this.leafIcon = var1;
- }
-
- public void setOpenIcon(Icon var1) {
- this.openIcon = var1;
- }
-
- public void setTextNonSelectionColor(Color var1) {
- this.textNonSelectionColor = var1;
- }
-
- public void setTextSelectionColor(Color var1) {
- this.textSelectionColor = var1;
- }
- }
-